<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./main.css">
    <link rel="icon" href="./source/image/icon.png">
    <title>JS 30: Flex Gallery</title>
</head>
<body>
    <section class="panels">
        <div class="panel panel__1">
            <p>Hey</p>
            <p>Let's</p>
            <p>Dance</p>
        </div>
        <div class="panel panel__2">
            <p>Give</p>
            <p>Take</p>
            <p>Receive</p>
        </div>
        <div class="panel panel__3">
            <p>Experience</p>
            <p>It</p>
            <p>Today</p>
        </div>
        <div class="panel panel__4">
            <p>Give</p>
            <p>All</p>
            <p>You can</p>
        </div>
        <div class="panel panel__5">
            <p>Life</p>
            <p>In</p>
            <p>Motion</p>
        </div>
    </section>

    <script>
        function toogleCardHandler() {
            this.classList.toggle('active');
            this.classList.contains('open-text') && this.classList.remove('open-text');
        }

        function openTextHandler(e) {
            if (e.propertyName !== 'flex-grow') return;

            if (this.classList.contains('active')) {
                this.classList.add('open-text');
            }
        }

        document.querySelectorAll('.panel').forEach(el => {
            el.addEventListener('click', toogleCardHandler);
            el.addEventListener('transitionend', openTextHandler)
        })
    </script>
</body>
</html>